<?php


namespace App\Services\AetherUpload;
use App\Services\AetherUpload\lib\ConfigMapper;
use Encore\Admin\Form\Field;

class LargeFileField extends Field
{
    public $view = 'large-file-field::large_file_upload';
    protected $group = 'file';
    public function group($group)
    {
        $this->group = $group;
        return $this;
    }
    public function render()
    {
        $route_preprocess = ConfigMapper::get('route_preprocess');
        $route_uploading = ConfigMapper::get('route_uploading');
        $name = $this->formatName($this->column);
        $this->script = <<<SRC
        $('#{$name}-resource').bootstrapFileInput();
        $('#{$name}-resource').change(function(){
            aetherupload('{$name}', this).setGroup('{$this->group}')
            .setSavedPathField('#{$name}-savedpath')
            .setPreprocessRoute('{$route_preprocess}')
            .setUploadingRoute('{$route_uploading}')
            .setLaxMode(false)
            .success()
            .upload('{$name}')
        });

SRC;
        return parent::render();
    }
}
